//
//  Jiankang_fenxi_tianxie_vc.m
//  ainkjj
//
//  Created by zhiyiLiu on 2020/3/12.
//  Copyright © 2020 zhiyiLiu. All rights reserved.
//

#import "Jiankang_fenxi_tianxie_vc.h"
#import "ClMarkButton.h"
#import "Jiankang_fenxi_jieguo_vc.h"
#import "WSDatePickerView.h"
#import "Bmi_setBabyBmi.h"

@interface Jiankang_fenxi_tianxie_vc ()
@property (nonatomic, strong)Bmi_setBabyBmi *current_bmi;



@end

@implementation Jiankang_fenxi_tianxie_vc
- (void)req_bmi_info{
    
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:app_code forKey:@"appCode"];
    [dict setObject:AuthSignin_model.sharedInstance.data.token forKey:@"token"];
    [dict setObject:self.device_id forKey:@"deviceId"];
    
    //sender.userInteractionEnabled = NO;
    //    __block QMUITips *qmui_tip = [QMUITips showLoading:@"请求中..." inView:self.navigationController.view];
    
    [PPHTTPRequest req:@"java/app/bmi/getBabyBmi" parameters:dict success:^(id response) {
        NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
        if ([error_code isEqualToString:@"0"]) {
            
            self.current_bmi = [Bmi_setBabyBmi mj_objectWithKeyValues:response];
            
            self.tizhong_tf.text = @(self.current_bmi.data.weight).stringValue;
            self.shengao_tf.text = @(self.current_bmi.data.height).stringValue;
            self.nv_btn.selected =   self.current_bmi.data.sex == 1 ;
            
            [self.selected_date_btn setTitle:self.current_bmi.data.birthday forState:UIControlStateNormal];;
            
        }
        else{
            
            
            [QMUITips showError:response[@"error_msg"]];
            
        }
        
    } failure:^(NSError *error) {
        [QMUITips showError:[error localizedDescription] ];
        
    }];
}


- (IBAction)chushengriqi_action:(UIButton *)sender {
    
    //年-月-日
    WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {
        
        NSString *dateString = [selectDate stringWithFormat:@"yyyy-MM-dd"];
        DLog(@"选择的日期：%@",dateString);
        [sender setTitle:dateString forState:UIControlStateNormal];
    }];
    datepicker.dateLabelColor = appMainColor;//年-月-日-时-分 颜色
    datepicker.datePickerColor = themeColor;//滚轮日期颜色
    datepicker.doneButtonColor = themeColor;//确定按钮的颜色
    datepicker.maxLimitDate = [NSDate date];
    [self.view endEditing:YES];
    [datepicker show];
}
- (IBAction)liji_fenxi_action:(UIButton *)sender {
   
    
    if ([[self.selected_date_btn currentTitle] isEqualToString:@"请选择出生日期"]) {
        [MBProgressHUD showTipMessageInView:@"请选择出生日期"];
        
        return;
    }
    if ([Anktool strIsBlank:self.tizhong_tf.text]) {
        [MBProgressHUD showTipMessageInView:@"请输入体重"];
        return;
    }
    
    if ([Anktool strIsBlank:self.shengao_tf.text]) {
        [MBProgressHUD showTipMessageInView:@"请输入身高"];
        return;
    }
    
   
  
    
    Jiankang_fenxi_jieguo_vc *vc= [[Jiankang_fenxi_jieguo_vc alloc]init];
    vc.w = self.tizhong_tf.text;
    vc.h = self.shengao_tf.text;
    vc.nan_nv = self.nan_btn.isSelected ? @"男" : @"女";
    vc.birth_date = self.selected_date_btn.currentTitle;
    
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = UIColor.groupTableViewBackgroundColor;
    // 设置单选按钮
    NSArray *radioArray = @[self.nan_btn, self.nv_btn];
    for (int i=0; i<radioArray.count; ++i)
    {
        CLMarkButton *button = radioArray[i];
        button.type = CLMarkTypeSingleRadio;
        button.groupId = 10001;
        button.tag = i;
        [button addTarget:self action:@selector(nan_nv_buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    [self nan_nv_buttonClick:self.nan_btn];
    
    self.title = @"填写健康信息";
    
    [self req_bmi_info];
}
- (void)nan_nv_buttonClick:(CLMarkButton *)sender{
    [sender buttonDidClick];
    DLog(@"%d", sender.selected);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
